<template>
	<el-container>
		<el-header>
			分销比例设置
		</el-header>
		<el-main style="background-color: #FFF">
			<el-form :model="form" :rules="formRules" ref="configForm" label-width="140px" label-position="left" v-loading="isLoading">
				<el-form-item label="店内(自购)佣金比例" prop="one_rate">
					<div>
						<div style="display: flex;">
							<el-input-number v-model="form.one_rate" :min="0.01" :max="100" :precision="2" :controls="false" />
							<div class="el-input-group__append">%</div>
						</div>
						<div class="el-form-item-help">

						</div>
					</div>
				</el-form-item>
				<el-form-item label="上级佣金比例" prop="two_rate">
					<el-input-number v-model="form.two_rate" :min="0.01" :max="100" :precision="2" :controls="false" />
					<div class="el-input-group__append">%</div>
				</el-form-item>
				<el-form-item label="上上级佣金比例" prop="three_rate">
					<el-input-number v-model="form.three_rate" :min="0.01" :max="100" :precision="2" :controls="false" />
					<div class="el-input-group__append">%</div>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit">保 存</el-button>
				</el-form-item>
			</el-form>
		</el-main>
	</el-container>
</template>

<script>
export default {
	name: "fenxiao-level",
	data() {
		return {
			isLoading: false,
			form: {
				one_rate: 0,
				two_rate: 0,
				three_rate: 0,
			},
		}
	},
	mounted() {
		this.getConfigData();
	},
	methods:{
		getConfigData() {
			this.isLoading = true;
			this.$API.fenxiao.level.info().then(res => {
				this.isLoading = false;
				if (res.code === 0) {
					if (typeof res.level_config != undefined) {
						this.form = res.data;
					}
					else {
						this.$message.error(res.message);
					}
				}
			})
		},
		onSubmit() {
			this.isLoading = true;
			this.$API.fenxiao.level.update(this.form).then(res => {
				this.isLoading = false;
				if (res.code === 0) {
					this.$message.success('保存成功');
				}
				else {
					this.$message.error(res.message);
				}
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.el-form-item-help{
	color: #AAA;
}
.el-input-group__append{
	border: none;
	width: auto;
}
</style>
